package au.edu.swin.swinvehicle.vehiclebooking;

/**
 * VehicleBooking entity
 * @version 1.0
 * @author Viet Bui
 * @lastmodify 2009-05-10
 */
import au.edu.swin.swinvehicle.bookingtype.BookingTypeEntity;
import au.edu.swin.swinvehicle.corporateclient.CorporateClientEntity;
import au.edu.swin.swinvehicle.driver.DriverEntity;
import au.edu.swin.swinvehicle.eventtype.EventTypeEntity;
import au.edu.swin.swinvehicle.manager.ManagerEntity;
import au.edu.swin.swinvehicle.vehicle.VehicleEntity;
import au.edu.swin.swinvehicle.vehicletype.VehicleTypeEntity;
import java.io.Serializable;
import java.sql.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@NamedQueries({
    @NamedQuery(name = "findAllVehicleBookings",
    query = "SELECT vb FROM VehicleBookingEntity vb"),
    @NamedQuery(name = "getVehicleBookingsByCriteria",
    query = " SELECT vb " +
    " FROM VehicleBookingEntity vb " +
    " WHERE 1 = 1 " +
    " AND (:isQueriedVehicleNull = true OR vb.vehicle = :queriedVehicle )" +
    " AND (:isQueriedDriverNull = true OR vb.driver = :queriedDriver )")
})
@Table(name = "VEHICLEBOOKING")
public class VehicleBookingEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column(length = 63, nullable = false)
    private String contactName;
    @Column(length = 15, nullable = false)
    private String contactPhone;
    @Column(length = 63)
    private String contactEmail;
    @Column(length = 63, nullable = false)
    private String customerName;
    @Column(nullable = false)
    private Date pickUpDate;
    @Column(length = 255)
    private String pickUpAddress;
    @Column(length = 255)
    private String dropOffAddress;
    @Column(nullable = false)
    private boolean taskCompleted = false;

    /*
    @Column(length = 63, nullable = false)
    private String bookingType;
    @Column(length = 63, nullable = false)
    private String eventType;
    @Column(length = 63, nullable = false)
    private String vehicleType;
     */
    @ManyToOne(optional = false, cascade = CascadeType.PERSIST)
    private BookingTypeEntity bookingType;
    @ManyToOne(optional = false, cascade = CascadeType.PERSIST)
    private EventTypeEntity eventType;
    @ManyToOne(optional = false, cascade = CascadeType.PERSIST)
    private VehicleTypeEntity vehicleType;
    @Column(length = 63)
    private String specialRequirement;
    @Column(length = 255)
    private String comment;
    @ManyToOne(optional = false, cascade = CascadeType.PERSIST)
    private VehicleEntity vehicle;
    @ManyToOne(optional = false, cascade = CascadeType.PERSIST)
    private DriverEntity driver;
    @ManyToOne(optional = false, cascade = CascadeType.PERSIST)
    private ManagerEntity manager;
    @ManyToOne(optional = false, cascade = CascadeType.PERSIST)
    private CorporateClientEntity corporateClient;

    /**
     * Default constructor
     */
    public VehicleBookingEntity() {
    }

    public VehicleBookingEntity(boolean taskCompleted, String contactName, String contactPhone, String contactEmail, String customerName, Date pickUpDate, String pickUpAddress, String dropOffAddress, BookingTypeEntity bookingType, EventTypeEntity eventType, VehicleTypeEntity vehicleType, String specialRequirement, String comment, DriverEntity driver, VehicleEntity vehicle, ManagerEntity manager, CorporateClientEntity corporateClient) {
        this(); // Call default constructor
        setContactName(contactName);
        setContactPhone(contactPhone);
        setContactEmail(contactEmail);
        setCustomerName(customerName);
        setPickUpDate(pickUpDate);
        setPickUpAddress(pickUpAddress);
        setDropOffAddress(dropOffAddress);
        setBookingType(bookingType);
        setEventType(eventType);
        setVehicleType(vehicleType);
        setSpecialRequirement(specialRequirement);
        setComment(comment);
        setDriver(driver);
        setVehicle(vehicle);
        setManager(manager);
        setCorporateClient(corporateClient);
        setTaskCompleted(taskCompleted);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getContactName() {
        return contactName;
    }

    public void setContactName(String contactName) {
        this.contactName = contactName;
    }

    public String getContactPhone() {
        return contactPhone;
    }

    public void setContactPhone(String contactPhone) {
        this.contactPhone = contactPhone;
    }

    public String getContactEmail() {
        return contactEmail;
    }

    public void setContactEmail(String contactEmail) {
        this.contactEmail = contactEmail;
    }

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public Date getPickUpDate() {
        return pickUpDate;
    }

    public void setPickUpDate(Date pickUpDate) {
        this.pickUpDate = pickUpDate;
    }

    public String getPickUpAddress() {
        return pickUpAddress;
    }

    public void setPickUpAddress(String pickUpAddress) {
        this.pickUpAddress = pickUpAddress;
    }

    public String getDropOffAddress() {
        return dropOffAddress;
    }

    public void setDropOffAddress(String dropOffAddress) {
        this.dropOffAddress = dropOffAddress;
    }

    public BookingTypeEntity getBookingType() {
        return bookingType;
    }

    public void setBookingType(BookingTypeEntity bookingType) {
        this.bookingType = bookingType;
    }

    public EventTypeEntity getEventType() {
        return eventType;
    }

    public void setEventType(EventTypeEntity eventType) {
        this.eventType = eventType;
    }

    public VehicleTypeEntity getVehicleType() {
        return vehicleType;
    }

    public void setVehicleType(VehicleTypeEntity vehicleType) {
        this.vehicleType = vehicleType;
    }

    public String getSpecialRequirement() {
        return specialRequirement;
    }

    public void setSpecialRequirement(String specialRequirement) {
        this.specialRequirement = specialRequirement;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public DriverEntity getDriver() {
        return driver;
    }

    public void setDriver(DriverEntity driver) {
        this.driver = driver;
    }

    public VehicleEntity getVehicle() {
        return vehicle;
    }

    public void setVehicle(VehicleEntity vehicle) {
        this.vehicle = vehicle;
    }

    public ManagerEntity getManager() {
        return manager;
    }

    public void setManager(ManagerEntity manager) {
        this.manager = manager;
    }

    public CorporateClientEntity getCorporateClient() {
        return corporateClient;
    }

    public void setCorporateClient(CorporateClientEntity corporateClient) {
        this.corporateClient = corporateClient;
    }

    public boolean isTaskCompleted() {
        return taskCompleted;
    }

    public void setTaskCompleted(boolean taskCompleted) {
        this.taskCompleted = taskCompleted;
    }
    // Only the VehicleBookingDetailedTO can be used to update the state of the Vehicle Booking entity

    public void setData(VehicleBookingDetailedTO to) {
        setId(to.getId());
        setContactName(to.getContactName());
        setContactPhone(to.getContactPhone());
        setContactEmail(to.getContactEmail());
        setCustomerName(to.getCustomerName());
        setPickUpDate(to.getPickUpDate());
        setPickUpAddress(to.getPickUpAddress());
        setDropOffAddress(to.getDropOffAddress());
        setSpecialRequirement(to.getSpecialRequirement());
        setComment(to.getComment());

    // This all to be done in the ManagerBean level
    //        setBookingType(to.getBookingType());
    //        setEventType(to.getEventType());
    //        setVehicleType(to.getVehicleType());
    //        setDriver(to.getDriver());
    //        setVehicle(to.getVehicle());
    //        setManager(to.getManager());
    //        setCorporateClient(to.getCorporateClient());
    }

    public VehicleBookingTO getData() {
        return new VehicleBookingTO(id, contactName, customerName, pickUpDate, pickUpAddress, bookingType.getId(), eventType.getId(),taskCompleted);
    }

    public VehicleBookingDetailedTO getDetailedData() {
        return new VehicleBookingDetailedTO(id, contactName, contactPhone, contactEmail, customerName, pickUpDate, pickUpAddress, dropOffAddress, bookingType.getId(), eventType.getId(), vehicleType.getId(), specialRequirement, comment, vehicle.getId(), driver.getId(), manager.getId(), corporateClient.getId(),taskCompleted);
    }

    @Override
    public String toString() {
        return "au.edu.swin.swinvehicle.corporateclient.CorporateClientEntity[id=" + id + "]";
    }
}